/*
 
Enterprise Social Network (ESN) is an open-source Java EE framework for
a social network application.

Copyright (C) 2006-07 (see CONTRIBUTORS file in project root)

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

*/

package esn.core.ejb.entity;

import java.util.*;
import java.io.*;

import javax.persistence.*;

/**
 * <p>Representation of a vertex in the social network
 * graph.</p>
 *  
 * @author Anirban Basu
 *
 */
@Entity
public class UserProfile implements Serializable {
	private static final long serialVersionUID = 1L;

	private Collection<ESNEdge> egressEdges = new ArrayList<ESNEdge>();
	private Collection<ESNEdge> ingressEdges = new ArrayList<ESNEdge>();
	
	/*
	 * TODO: Use embedded primary keys with UUID style generation
	 * to cater for a larger key space. 64-bit long ids do not
	 * provide big enough key space. This should be the primary
	 * key strategy throughout ESN core. How big should the key
	 * space be? 1024-bit? Should watch the compromise between
	 * computation power versus key space size.
	 */
	private long id;
	private UserAuthentication authentication;
	
	/*
	 * Instead of creating a different class for different
	 * parts of the name, each such part is made a member of this
	 * class. This strategy works better during a fetch operation
	 * on the database because of presence of data in a single
	 * table: hence, lesser joins and nested queries. 
	 */
	/* BEGIN NAME BLOCK */
	private String namePrefixes;
	private String givenName;
	private String middleNames;
	private String familyName;
	private String maidenNames;
	private String nameSuffixes;
	/* END NAME BLOCK */
	
	private double globalTrustScore = 0.0D;
	
	/**
	 * Accessor for egress (outgoing) edges.
	 * 
	 * @return
	 */
	@OneToMany(mappedBy="source")
	public Collection<ESNEdge> getEgressEdges() {
		return egressEdges;
	}
	
	/**
	 * Mutator for egress (outgoing) edges.
	 * 
	 * @param egressEdges
	 */
	public void setEgressEdges(Collection<ESNEdge> egressEdges) {
		this.egressEdges = egressEdges;
	}
	
	/**
	 * Accessor for ingress (incoming) edges.
	 * 
	 * @return
	 */
	@OneToMany(mappedBy="destination")
	public Collection<ESNEdge> getIngressEdges() {
		return ingressEdges;
	}
	
	/**
	 * Mutator for ingress (incoming) edges.
	 * 
	 * @param ingressEdges
	 */
	public void setIngressEdges(Collection<ESNEdge> ingressEdges) {
		this.ingressEdges = ingressEdges;
	}
	
	/**
	 * Accessor for the primary key.
	 * 
	 * @return
	 */
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	public long getId() {
		return id;
	}
	/**
	 * Mutator for the primary key.
	 * 
	 * @param id
	 */
	public void setId(long id) {
		this.id = id;
	}
	
	/**
	 * Accessor for user authentication object.
	 * 
	 * @return
	 */
	@OneToOne(cascade={CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.REMOVE})
	@JoinColumn(name="authentication_id")
	public UserAuthentication getAuthentication() {
		return authentication;
	}
	
	/**
	 * Mutator for user authentication object.
	 * 
	 * @param authentication
	 */
	public void setAuthentication(UserAuthentication authentication) {
		this.authentication = authentication;
	}

	/**
	 * @return Returns the familyName.
	 */
	public String getFamilyName() {
		return familyName;
	}

	/**
	 * @param familyName The familyName to set.
	 */
	public void setFamilyName(String familyName) {
		this.familyName = familyName;
	}

	/**
	 * @return Returns the givenName.
	 */
	public String getGivenName() {
		return givenName;
	}

	/**
	 * @param givenName The givenName to set.
	 */
	public void setGivenName(String givenName) {
		this.givenName = givenName;
	}

	/**
	 * @return Returns the maidenNames.
	 */
	@JoinColumn(nullable=true)
	public String getMaidenNames() {
		return maidenNames;
	}

	/**
	 * @param maidenNames The maidenNames to set.
	 */
	public void setMaidenNames(String maidenNames) {
		this.maidenNames = maidenNames;
	}

	/**
	 * @return Returns the middleNames.
	 */
	@JoinColumn(nullable=true)
	public String getMiddleNames() {
		return middleNames;
	}

	/**
	 * @param middleNames The middleNames to set.
	 */
	public void setMiddleNames(String middleNames) {
		this.middleNames = middleNames;
	}

	/**
	 * @return Returns the namePrefixes.
	 */
	@JoinColumn(nullable=true)
	public String getNamePrefixes() {
		return namePrefixes;
	}

	/**
	 * @param namePrefixes The namePrefixes to set.
	 */
	public void setNamePrefixes(String namePrefixes) {
		this.namePrefixes = namePrefixes;
	}

	/**
	 * @return Returns the nameSuffixes.
	 */
	@JoinColumn(nullable=true)
	public String getNameSuffixes() {
		return nameSuffixes;
	}

	/**
	 * @param nameSuffixes The nameSuffixes to set.
	 */
	public void setNameSuffixes(String nameSuffixes) {
		this.nameSuffixes = nameSuffixes;
	}

	/**
	 * @return Accessor for globalTrustScore.
	 */
	@JoinColumn(nullable=false)
	public double getGlobalTrustScore() {
		return globalTrustScore;
	}

	/**
	 * Mutator method for globalTrustScore
	 * @param globalTrustScore
	 */
	public void setGlobalTrustScore(double globalTrustScore) {
		this.globalTrustScore = globalTrustScore;
	}
	
}
